package com.src.myapplication.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.src.myapplication.ui.IView;
import com.src.myapplication.ui.contor.LoginPresenter;

import butterknife.ButterKnife;

/**
 * Created by zhonghang on 16/8/31.
 */

public abstract class BaseFragmentSwp extends Fragment implements IView, SwipeRefreshLayout.OnRefreshListener {
    private SwipeRefreshLayout mSwipeRefreshLayout;
    private LoginPresenter mLoginPresenter;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutId(), null);
        mLoginPresenter = new LoginPresenter(this);
        ButterKnife.bind(view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initData(view);
        initView(view);



    }

    protected abstract void initData(View view);

    public void initView(View view) {
        //下拉刷新

        mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(getid());
        mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_green_light, android.R.color.holo_red_light, android.R.color.holo_orange_light);
        mSwipeRefreshLayout.setOnRefreshListener(this);
        onRefresh();

    }

    public abstract int getLayoutId();


    abstract public int getid();


    @Override
    public void refresh() {//刷新
        mSwipeRefreshLayout.setRefreshing(true);
    }

    @Override
    public void stoprefresh() {//停止刷新
        mSwipeRefreshLayout.setRefreshing(false);
    }

    @Override
    public void onRefresh() {
        mLoginPresenter.lodData();

    }


}
